<template>
  <div class="tabbar">
    <ul>
      <li
        v-for="(item, index) in routerList"
        :key="index"
        @click="swicthTab(item.path)"
        :class="$route.path.includes(item.path) ? 'imgactive' : ''"
      >
        <div>
          <van-icon :name="item.active" size="30px" />
        </div>
        <span>{{ item.title }}</span>
      </li>
    </ul>
  </div>
</template>

<script>
export default {
  data() {
    return {
      routerList: [
        {
          title: "首页",
          path: "/home",
          active: "wap-home-o",
        },
        {
          title: "分类",
          path: "/shoplist",
          active: "cluster-o",
        },
        {
          title: "购物车",
          path: "/cart",
          active: "shopping-cart-o",
        },
        {
          title: "我的",
          path: "/my",
          active: "user-o",
        },
      ],
    }
  },

  methods: {
    swicthTab(path) {
      console.log(path)
      console.log(this.$route.path)
      if (path === this.$route.path) return
      // this.$router.push(path)
      this.$router.replace(path)
    },
  },
}
</script>

<style scoped>
.tabbar {
  position: fixed;
  width: 100%;
  /* height: 0px; */
  background-color: #fff;
  /* height: 2rem; */
  bottom: 0px;
}

.tabbar ul {
  display: flex;
  justify-content: space-around;
  width: 100%;
  height: 100%;
}

.imgactive {
  color: orange;
}

.tabbar ul li {
  /* flex: 1; */
  display: flex;
  flex-direction: column;
}
</style>
